package singleton;

/**
 * 懒汉式
 * 使用时再创建
 */
public class Singleton04 {

    private static Singleton04 INSTANCE;

    private Singleton04(){}

    public static Singleton04 getInstance(){
        //并发异常！
        if (INSTANCE == null){
            INSTANCE = new Singleton04();
        }
        return INSTANCE;
    }


    public static void main(String[] args) {
        Singleton04 i1 = Singleton04.getInstance();
        Singleton04 i2 = Singleton04.getInstance();
        System.out.println(i1 == i2);
    }
}
